
#define BOOST_TEST_MAIN
//#define BOOST_TEST_MODULE tcp_data_handler

#include <boost/test/included/unit_test.hpp>

#include "observer_manager.h"


BOOST_AUTO_TEST_SUITE(test_observer_manager) ;

class myobserver : public event_observer
{
public:
    myobserver(observer_manager* manager):m_manager(manager),m_count(rand()) 
    { 
        m_manager->subscribe(1,this) ;
    } ;
    void on_event(int event_id,void* arg) 
    { 
        m_manager->unsubscribe(1,this) ;
        printf("%d %s event:%d arg:%p\n",m_count,__FUNCTION__,event_id,arg) ; 
    } ;

private:
    observer_manager* m_manager ;
    int m_count ;
} ;



BOOST_AUTO_TEST_CASE(test_function)
{
    observer_manager manager ;
    myobserver o1(&manager),o2(&manager) ;
    printf("publish event 1\n") ;
    manager.publish(1,NULL) ;
    printf("publish event 2\n") ;
    manager.publish(2,NULL) ;
    
    manager.unsubscribe(1,&o1) ;
    printf("publish event 1\n") ;
    manager.publish(1,NULL) ;



    //BOOST_REQUIRE(lua_manager.load("plugin_login.lua")==0) ;

   
    //BOOST_CHECK(conn.get_status() == tcp_data_handler::STATUS_CONNECTED) ;


}



BOOST_AUTO_TEST_SUITE_END() ;

